package com.byxy.ssm.demo.service.impl;

import java.io.File;
import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import com.byxy.ssm.demo.dao.ItemsDao;
import com.byxy.ssm.demo.entity.Items;
import com.byxy.ssm.demo.service.ItemsService;

@Service
@Transactional
public class ItemsServiceImpl implements ItemsService {
	
	@Autowired
	private ItemsDao ItemsDao;


	public List<Items> getAll() {
		return ItemsDao.getAlList();
	}


	public void add(Items items, MultipartFile multipartFile, HttpServletRequest request) {
		try {
			multipartFile.transferTo(new File(request.getServletContext().getRealPath("images"),multipartFile.getOriginalFilename()));
			System.err.println(request.getServletContext().getRealPath("images"));
		} catch (IllegalStateException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		items.setImg("images/"+multipartFile.getOriginalFilename());
		ItemsDao.add(items);
		
	}

}
